//
//  UIImageView+LZImageView.m
//  LZMall
//
//  Created by apple on 2018/5/21.
//  Copyright © 2018年 LZZJStore. All rights reserved.
//

#import "UIImageView+LZImageView.h"

@implementation UIImageView (LZImageView)

//检验字符串是否有中文
- (BOOL)checkIsChinese:(NSString *)string{
    for (int i=0; i<string.length; i++) {
        unichar ch = [string characterAtIndex:i];
        if (0x4E00 <= ch  && ch <= 0x9FA5) {
            return YES;
        }
    }
    return NO;
}

- (void)LZsetImageWithImagePath:(NSString *)imagePath
               placeholderImage:(UIImage *)placeHolderImage
{
    
    if ([self checkIsChinese:imagePath]) {
//       imagePath = [imagePath stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
        imagePath = [imagePath stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
    }

    if (imagePath == nil) {
        [self sd_setImageWithURL:[NSURL URLWithString:@""]
             placeholderImage:placeHolderImage];
    }else{
    [self sd_setImageWithURL:[NSURL URLWithString:imagePath]
         placeholderImage:placeHolderImage];
    }
}

@end
